package com.sptus.web.util;

import lombok.Data;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.WeekFields;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public class YearlyDateGenerator {
    public static void main(String[] args) {
        int targetYear = 2025;
        List<DailyData> yearlyData = generateYearlyData(targetYear);
        System.out.println(yearlyData);
        // 示例：输出第75天的数据（对应3月13日）
        System.out.println(yearlyData.get(74)); 
        // 输出：DailyData{date='13', week='Thu', month='Mar', weekOfYear=11}
    }

    public static List<DailyData> generateYearlyData(int year) {
        List<DailyData> dataList = new ArrayList<>();
        LocalDate startDate = LocalDate.of(year, Month.JANUARY, 1);
        LocalDate endDate = LocalDate.of(year + 1, Month.JANUARY, 1);

        // 定义格式器
        DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("MMM", Locale.ENGLISH);
        DateTimeFormatter weekFormatter = DateTimeFormatter.ofPattern("E", Locale.ENGLISH);
        WeekFields weekFields = WeekFields.of(Locale.US); // 使用美国周定义（周日为一周起始）

        while (startDate.isBefore(endDate)) {
            // 获取数据项
            String date = String.valueOf(startDate.getDayOfMonth());
            String week = startDate.format(weekFormatter);
            String month = startDate.format(monthFormatter);
            int weekOfYear = startDate.get(weekFields.weekOfWeekBasedYear());

            dataList.add(new DailyData(date, week, month, weekOfYear,0));
            startDate = startDate.plusDays(1);
        }

        return dataList;
    }

    @Data
    // 数据存储类
   public static class DailyData {
        private String date;
        private String week;
        private String month;
        private int weekOfYear;
        private int data;

        public DailyData(String date, String week, String month, int weekOfYear,int data) {
            this.date = date;
            this.week = week;
            this.month = month;
            this.weekOfYear = weekOfYear;
            this.data = data;
        }

        @Override
        public String toString() {
            return String.format(
                "DailyData{date='%s', week='%s', month='%s', weekOfYear=%d}",
                date, week, month, weekOfYear
            );
        }

    }
}